<?php
class Tourismkeyword extends CS_Controller
{
    private $typeArray = array(
    	0 => '无', 1 => '景区',2 => '商品', 
        3 => '酒店', 4 => '线路', 5 => '就近送'
    );
    
    private $fromArray = array(
        0 => '无', 1 => 'pc',2 => 'phone_android',
        3 => 'phone_ios',4 => 'phone_win', 5 => 'wap_android',
        6 => 'wap_ios',7 => 'wap_win'
    );
    
    private $logicArray = array(
    	'-1' => '删除',
        '1'  => '正常'
    );
    
    public function _init()
    {
        $this->load->library('pagination');
        $this->load->model('tourism_key_word_model', 'tourism_key_word');
    }
    
    public function grid($pg = 1)
    {
        $page_num = 20;
        $num = ($pg - 1) * $page_num;
        $config['first_url'] = base_url('tourismkeyword/grid').$this->pageGetParam($this->input->get());
        $config['suffix'] = $this->pageGetParam($this->input->get());
        $config['base_url'] = base_url('tourismkeyword/grid');
        $config['total_rows'] = $this->tourism_key_word->total($this->input->get());
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_list'] = $this->pagination->create_links();
        $data['page_list'] = $this->tourism_key_word->page_list($page_num, $num, $this->input->get());
        $data['all_rows'] = $config['total_rows'];
        $data['pg_now'] = $pg;
        $data['url'] = $this->pageGetParam($this->input->get());
        $data['type'] = $this->typeArray;
        $data['from'] = $this->fromArray;
        $data['logic'] = $this->logicArray;
        $this->load->view('tourismkeyword/grid', $data);
    }
    
    public function delete($id,$pg_now)
    {
        if (!admin_priv($this->actionList, 'tourism_search_delete')) {
           $this->error('tourismkeyword/grid', '', '没有此权限');
        }
        $is_delete = $this->tourism_key_word->deleteById($id);
        if ($is_delete) {
            $this->success('tourismkeyword/grid/'.$pg_now, '', '删除成功！');
        } else {
            $this->error('tourismkeyword/grid/'.$pg_now, '', '删除失败！');
        }
    }
    
     /**
     * 批量删除
     */
    public function batchDelete() {
    
        if (!admin_priv($this->actionList, 'tourism_search_batch_delete')) {
            $this->jsonMessage('没有此权限');
        }
        $pg = (int)$this->input->post('pg');
        $idArray = $this->input->post('id');
        if (count($idArray) <=0) {
            $this->jsonMessage('请选择商品');
        }
        $is_delete = $this->tourism_key_word->deleteById($idArray);
        if ($is_delete) {
            $this->session->set_flashdata('success', '操作成功!');
            $this->jsonMessage('',site_url('tourismkeyword/grid/'.$pg));
        } 
        $this->session->set_flashdata('error', '操作失败!');
        $this->jsonMessage('操作失败');
    }
}